package cc.messcat.service.fupin;

import cc.messcat.common.model.Pager;
import cc.messcat.common.service.BaseServiceImpl;
import cc.messcat.dao.fupin.WorkCircleDao;
import cc.messcat.dao.system.UserDao;
import cc.messcat.entity.circle.WorkCircle;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class WorkCircleServiceImpl extends BaseServiceImpl<WorkCircle> implements WorkCircleService {

	@Autowired
	private WorkCircleDao workCircleDao;
	
	@Autowired
	private UserDao userDao;
	
	/**
	 * 获取内容
	 */
	@Override
	public Pager listCircle(Integer pageNo, Integer pageSize,WorkCircle circle) {
	    String tagCondition = StringUtils.isNotBlank(circle.getTag()) ? " and tag = '"+circle.getTag()+"'" : "";
		return workCircleDao.getPagerByHql(pageNo, pageSize, " from WorkCircle where 1=1 "+tagCondition+" order by editTime desc", null);
	}

	/**
	 * 以用户id获取动态
	 * @return
	 */
	@Override
	public Pager listCircle(Integer pageNo, Integer pageSize, Long id,WorkCircle circle) {
		
		if(userDao.get(id) == null) {
			return new Pager(pageSize,pageNo,0,new ArrayList<>(0));
		}
        String tagCondition = StringUtils.isNotBlank(circle.getTag()) ? " and tag = '"+circle.getTag()+"'" : "";
		return workCircleDao.getPagerByHql(pageNo, pageSize, " from WorkCircle where user.id="+id+ tagCondition + "  order by editTime desc", null);
	}

    @Override
    public Long addCircle(WorkCircle circle) {
	    return workCircleDao.addCircle(circle);
    }


}
